package insight.google.game.era.client.proxy;

import java.util.Collection;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.directwebremoting.proxy.ScriptProxy;


import insight.google.game.era.bo.GameActionLog;
import insight.google.game.era.bo.GameRoom;
import insight.google.game.era.bo.GameUser;
import insight.google.game.era.bo.card.GameCard;
import insight.google.game.era.dto.GameRoomDTO;

public class RoomClientProxyImpl implements RoomClientProxy {

	/**
	 * 
	 */
	
	private static RoomClientProxyImpl instance = new RoomClientProxyImpl();
	
	private RoomClientProxyImpl() {
		
	}
	
	public static RoomClientProxyImpl getInstance(){
		return instance;
	}

	public void doRoomInit(ScriptProxy userProxy, String jsComponentId,
			GameRoom gameRoom, long dataVersion) {
        Object[] param = new Object[2];
        param[0] = gameRoom;
        param[1] = dataVersion;
		userProxy.addFunctionCall("componentExecFunction",jsComponentId,"doInitialize",param);
		//userProxy.addFunctionCall("componentExecFunctionWithCall",jsComponentId,"doInitialize",gameRoom);
	}

	public void gameOver(ScriptProxy userProxy, String jsComponentId) {
		// TODO Auto-generated method stub

	}

	public void notifyUserAction(ScriptProxy userProxy, String jsComponentId) {
		// TODO Auto-generated method stub

	}

	public void notifyUserJoined(ScriptProxy userProxy, String jsComponentId,
			GameUser newUser, long dataVersion) {
        Object[] param = new Object[2];
        param[0] = newUser;
        param[1] = dataVersion;
		userProxy.addFunctionCall("componentExecFunction", jsComponentId, "userJoined", param);
		//userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "userJoined", newUser);
	}

	public void setReadyForStart(ScriptProxy userProxy, String jsComponentId) {
		userProxy.addFunctionCall("componentExecFunctionWithCall",jsComponentId,"readyToStart","");

	}

	@Override
	public void publicDataVersion(ScriptProxy userProxy, String jsComponentId,
			long dataVersion) {
		// TODO Auto-generated method stub
		userProxy.addFunctionCall("componentExecFunctionWithCall",jsComponentId,"updateDataVersion",dataVersion);
	}

	@Override
	public void errorMsgShow(ScriptProxy userProxy, String jsComponentId,
			String error) {
		// TODO Auto-generated method stub
		userProxy.addFunctionCall("componentExecFunctionWithCall",jsComponentId,"errorMsgShow", error);
	}

	@Override
	public void notifyActiveUser(ScriptProxy userProxy, String jsComponentId,
			GameUser activeUser) {
		// TODO Auto-generated method stub
		userProxy.addFunctionCall("componentExecFunctionWithCall",jsComponentId,"showCurrentActiveUser",activeUser);
	}

	@Override
	public void notifyUserLifeCount(ScriptProxy userProxy,
			String jsComponentId, GameUser activeUser, int lifeCount, boolean isAddLife) {
		// TODO Auto-generated method stub
        Object[] param = new Object[3];
        param[0] = activeUser;
        param[1] = lifeCount;
        param[2] = isAddLife;
		userProxy.addFunctionCall("componentExecFunction", jsComponentId, "showActiveUserLife", param);
	}
	@Override
	public void notifyUserCardCount(ScriptProxy userProxy, String jsComponentId,
			HashMap<String, String> data) {
		 userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "setCardCountToShow", data);
		
	}

	@Override
	public void notifyUserEquipementCard(ScriptProxy userProxy,
			String jsComponentId, HashMap<String, Collection<GameCard>> data) {
		userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "setEquipementCardToShow", data);
		
	}

	@Override
	public void notifyUserPlayedCard(ScriptProxy userProxy,
			String jsComponentId, HashMap<String, GameCard> data) {
		userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "setPlayedCardToShow", data);
		
	}

	@Override
	public void updateGameLog(ScriptProxy userProxy, String jsComponentId,
			List<GameActionLog> gameLogList) {
		userProxy.addFunctionCall("componentExecFunctionWithCall",jsComponentId, "updateGameLog", gameLogList);
		
	}

	@Override
	public void showRoomUsers(ScriptProxy userProxy, String jsComponentId,
			Collection<GameUser> data) {
		userProxy.addFunctionCall(
				"componentExecFunctionWithCall", jsComponentId,
				"showUsers", data);
		
	}

	@Override
	public void showGameResult(ScriptProxy userProxy, String jsComponentId, List<Map> data) {
		userProxy.addFunctionCall(
				"componentExecFunctionWithCall", jsComponentId,
				"showResult", data);
		
	}

	public void doRoomRefresh(ScriptProxy userProxy, String jsComponentId,
			GameRoom gameRoom, long dataVersion) {
        Object[] param = new Object[2];
        param[0] = gameRoom;
        param[1] = dataVersion;
		userProxy.addFunctionCall("componentExecFunction",jsComponentId,"roomUIUpdate",param);
		//userProxy.addFunctionCall("componentExecFunctionWithCall",jsComponentId,"doInitialize",gameRoom);
	}

	@Override
	public void activeHangUser(ScriptProxy userProxy, String jsComponentId) {
		userProxy.addFunctionCall(
				"componentExecFunctionWithCall", jsComponentId,
				"activeHangUser", "");
		
	}
}
